package com.apobates.jforum2.troll.accounts;

import com.apobates.jforum2.troll.regular.MemberGroupEnum;
import com.apobates.jforum2.troll.regular.MemberRoleEnum;
import java.util.EnumMap;
import java.util.Objects;
import java.util.Optional;

/**
 * 用户样式类
 * @author xiaofanku
 * @since 20201120
 */
public class MemberStyle {
    private final static EnumMap<MemberRoleEnum, String> ROLE_STYLE = new EnumMap<>(MemberRoleEnum.class);
    private final static EnumMap<MemberGroupEnum, String> GROUP_STYLE = new EnumMap<>(MemberGroupEnum.class);

    static {
        ROLE_STYLE.put(MemberRoleEnum.BM, "moderator");
        ROLE_STYLE.put(MemberRoleEnum.MASTER, "master");
        ROLE_STYLE.put(MemberRoleEnum.ADMIN, "admin");
        //
        GROUP_STYLE.put(MemberGroupEnum.CARD, "general");
        GROUP_STYLE.put(MemberGroupEnum.VIP, "vip");
        GROUP_STYLE.put(MemberGroupEnum.GUEST, "guest");
        GROUP_STYLE.put(MemberGroupEnum.SPIDER, "spider");
        GROUP_STYLE.put(MemberGroupEnum.ROBOT, "robot");
        GROUP_STYLE.put(MemberGroupEnum.ANONY, "anony");
        GROUP_STYLE.put(MemberGroupEnum.LEADER, "manager");
    }
    //允许参数为null吗?
    public static String get(MemberRoleEnum mrole, MemberGroupEnum mgroup) {
        Objects.requireNonNull(mrole);
        Objects.requireNonNull(mgroup);
        return Optional.ofNullable(ROLE_STYLE.get(mrole)).or(()-> Optional.ofNullable(GROUP_STYLE.get(mgroup))).orElse("");
    }

    private MemberStyle() throws Exception{
        throw new Exception("不需要实化公共工具类");
    }
}